package cn.mw.cmdb.service.impl;

import cn.mw.cmdb.entity.MwCMDBConfigInfo;
import cn.mw.cmdb.mongoMapper.MwCMDBConfigMapper;
import cn.mw.components.mongodb.tool.CriteriaWrapper;
import com.alibaba.nacos.common.utils.CollectionUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

/*
 * cmdb配置管理Server
 */
@Slf4j
public class MwCMDBConfigImpl extends ModelBaseServiceImpl<MwCMDBConfigInfo, Object> {

    public static final String ID = "mwCMDBConfig";

    private MwCMDBConfigMapper mwCMDBConfigMapper;

    private CmdbServiceManage cmdbServiceManage;


    public MwCMDBConfigImpl(CmdbServiceManage cmdbServiceManage, MwCMDBConfigMapper mwCMDBConfigMapper) {
        this.mwCMDBConfigMapper = mwCMDBConfigMapper;
        this.cmdbServiceManage = cmdbServiceManage;
    }

    @Override
    public MwCMDBConfigInfo genObject() {
        return new MwCMDBConfigInfo();
    }


    @Override
    Object doAdd(MwCMDBConfigInfo param) throws Exception {
        return null;
    }

    @Override
    boolean doUpdate(MwCMDBConfigInfo param) throws Exception {
        return false;
    }

    @Override
    boolean doRemove(MwCMDBConfigInfo param) throws Exception {
        return false;
    }

    @Override
    Object doBatchAdd(Object params) throws Exception {
        return null;
    }

    @Override
    boolean doBatchUpdate(Object params) throws Exception {
        return false;
    }

    @Override
    MwCMDBConfigInfo doSelectById(Object id) throws Exception {
        return null;
    }

    @Override
    List<MwCMDBConfigInfo> doSelectList(Object param) throws Exception {

        return null;
    }

    @Override
    boolean doBatchRemove(Object params) throws Exception {
        return false;
    }

    public MwCMDBConfigInfo doSelectByKey(String configKey) throws Exception {
        MwCMDBConfigInfo cmdbConfigInfo = new MwCMDBConfigInfo();
        Query query = new Query(CriteriaWrapper.where(MwCMDBConfigInfo::getConfigKey).is(configKey));
        List<MwCMDBConfigInfo> objects = mwCMDBConfigMapper.find(query);
        if (CollectionUtils.isNotEmpty(objects)) {
            cmdbConfigInfo = objects.get(0);
        }
        return cmdbConfigInfo;
    }

}

